import 'package:cook_dinner/config/include.dart';
import 'package:flutter/material.dart';

class LoginNav extends StatelessWidget {
  const LoginNav({Key? key, required this.child, this.cur = 0})
      : super(key: key);
  final Widget child;
  final int cur;

  @override
  Widget build(BuildContext context) {
    return ClipPath(
      clipper: cur == 0 ? LeftNavPath() : RightNavPath(),
      child: child,
    );
  }
}

class LeftNavPath extends CustomClipper<Path> {
  double val = 20.rpx;

  @override
  Path getClip(Size size) {
    Path path = Path();

    path.moveTo(0, size.height);
    path.lineTo(0, val);
    path.quadraticBezierTo(0, 0, val, 0);
    path.lineTo(size.width / 2 - val, 0);
    path.quadraticBezierTo(size.width / 2, 0, size.width / 2, val);
    path.lineTo(size.width / 2, size.height - val * 2);
    path.quadraticBezierTo(size.width / 2, size.height - val,
        size.width / 2 + val, size.height - val);
    path.lineTo(size.width - val, size.height - val);
    path.quadraticBezierTo(
        size.width, size.height - val, size.width, size.height);

    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return true;
  }
}

class RightNavPath extends CustomClipper<Path> {
  double val = 20.rpx;

  @override
  Path getClip(Size size) {
    Path path = Path();

    path.moveTo(0, size.height);
    path.quadraticBezierTo(0, size.height - val, val, size.height - val);
    path.lineTo(size.width / 2 - val, size.height - val);
    path.quadraticBezierTo(size.width / 2, size.height - val, size.width / 2,
        size.height - val * 2);
    path.lineTo(size.width / 2, val);
    path.quadraticBezierTo(size.width / 2, 0, size.width / 2 + val, 0);
    path.lineTo(size.width - val, 0);
    path.quadraticBezierTo(size.width, 0, size.width, val);
    path.lineTo(size.width, size.height);
    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return true;
  }
}
